package com.sky.service.impl;

import com.sky.constant.StatusConstant;
import com.sky.mapper.DishMapper;
import com.sky.mapper.SetmealMapper;
import com.sky.service.WorkSpaceService;
import com.sky.vo.DishOverViewVO;
import com.sky.vo.SetmealOverViewVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class WorkSpaceServiceImpl implements WorkSpaceService {

    @Autowired
    private SetmealMapper setmealMapper;

    @Autowired
    private DishMapper dishMapper;

    /**
     * 查询套餐总览数据
     * @return
     */
    @Override
    public SetmealOverViewVO overviewSetmeals() {
        // 查询套餐总记录数
        List<Map<String, Object>> mapList = setmealMapper.countStatus();
        SetmealOverViewVO setmealOverViewVO = new SetmealOverViewVO();
        for (Map<String, Object> stringObjectMap : mapList) {
            Integer status = (Integer) stringObjectMap.get("status");
            if (status.equals(StatusConstant.ENABLE)){
                Number sold = (Number) stringObjectMap.get("total");
                setmealOverViewVO.setSold(sold.intValue());
            }
            if (status.equals(StatusConstant.DISABLE)){
                Number discontinued = (Number) stringObjectMap.get("total");
                setmealOverViewVO.setDiscontinued(discontinued.intValue());
            }
        }
        return setmealOverViewVO;
    }

    @Override
    public DishOverViewVO overviewDishes() {
        List<Map<String, Object>> mapList = dishMapper.countStatus();
        DishOverViewVO dishOverViewVO = new DishOverViewVO();
        for (Map<String, Object> stringObjectMap : mapList) {
            Integer status = (Integer) stringObjectMap.get("status");
            if (status.equals(StatusConstant.ENABLE)){
                Number sold = (Number) stringObjectMap.get("total");
                dishOverViewVO.setSold(sold.intValue());
            }
            if (status.equals(StatusConstant.DISABLE)){
                Number discontinued = (Number) stringObjectMap.get("total");
                dishOverViewVO.setDiscontinued(discontinued.intValue());
            }
        }
        return dishOverViewVO;
    }
}
